Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when computing <ol><li> numbering, ignore non-<li> previous siblings #183

Conversation

chrispy-snps
Copy link
Collaborator

Currently, numbering for <li> items inside <ol> count all previous siblings when computing the number:

import markdownify

html = """
<ol>
  <!--comment-->
  <li>a</li>
  <div/>
  <li>b</li>
</ol>
"""

print(markdownify.MarkdownConverter().convert(html))
# 2. a
# 4. b

This pull request updates the code to consider only preceding <li> elements:

print(markdownify.MarkdownConverter().convert(html))
# 1. a
# 2. b

A unit test is added to check this case.

@chrispy-snps chrispy-snps requested a review from AlexVonB February 1, 2025 14:03
Copy link
Collaborator

@AlexVonB AlexVonB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Could be quadratic and take much compute on very(!) long lists, but that should be no problem in the day-to-day usecases.

@chrispy-snps
Copy link
Collaborator Author

Thanks @AlexVonB!

I was also mindful of the quadratic approach and I admit this fix still makes me somewhat uncomfortable, but we can always improve the code if someone really finds a case where this matters. :)

@chrispy-snps chrispy-snps merged commit c52a50e into matthewwithanm:develop Feb 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants